package com.lzw.d25bingso.tools;

import com.lzw.d25bingso.bean.Company;
import com.lzw.d25bingso.bean.Industry;
import com.lzw.d25bingso.bean.Viewpagers;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lzw on 2017/5/16.
 */

public class PaseJson {

    public static List<Viewpagers> pase(String jsonStr) {
        List<Viewpagers> data = null;
        if (jsonStr!=null){
            data = new ArrayList<>();
            try {
                JSONObject object = new JSONObject(jsonStr);
                JSONArray array = object.getJSONArray("viewpager");
                for (int i = 0;i<array.length();i++){
                    JSONObject object1 = array.getJSONObject(i);
                    String banner = object1.getString("banner");
                    data.add(new Viewpagers(banner));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return data;
    }

    public static List<Industry> paseIndustry(String jsonStr) {
        List<Industry> data = null;
        if (jsonStr!=null){
            data = new ArrayList<>();
            try {
                JSONObject object = new JSONObject(jsonStr);
                JSONArray array = object.getJSONArray("industry");
                for (int i = 0;i<array.length();i++){
                    JSONObject object1 = array.getJSONObject(i);
                    String id = object1.getString("id");
                    String name = object1.getString("name");
                    String imgurl = object1.getString("imgurl");
                    data.add(new Industry(id,name,imgurl));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        return  data;
    }

    public static List<Company> paseCompany(String jsonStr) {

        /**
         * private String company;
         private String  industryid;
         private String industryname;
         private String logo;
         private String summary;
         private String  imgurl;
         private String  idownload;
         private String updatetime;
         private String version;
         private String level;
         private String  size;
         */
        List<Company> data = null;
        if (jsonStr!=null){
            data = new ArrayList<>();
            try {
                JSONObject object = new JSONObject(jsonStr);
                JSONArray array = object.getJSONArray("companys");
                for (int i = 0;i<array.length();i++){
                    JSONObject object1 = array.getJSONObject(i);
                    String company = object1.getString("company");
                    String industryid = object1.getString("industryid");
                    String industryname = object1.getString("industryname");
                    String logo = object1.getString("logo");
                    String summary = object1.getString("summary");
                    String imgurl = object1.getString("imgurl");
                    String idownload = object1.getString("idownload");
                    String updatetime = object1.getString("updatetime");
                    String version = object1.getString("version");
                    String level = object1.getString("level");
                    String size = object1.getString("size");
                    data.add(new Company( company,  industryid,  industryname,  logo,  summary,  imgurl,  idownload,  updatetime,  version,  level,  size));


                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        return data;
    }
}
